/**
 * Copyright (c) 2011
 * Sven Wagner-Boysen
 *
 * This code is proprietary software within the 
 * company Signavio GmbH.
 *  
 **/

/**
 * Define Namespaces
 */
if(!Signavio){ var Signavio = {}; };
if(!Signavio.Portal){  Signavio.Portal = {}; };
if(!Signavio.Portal.Analytics){  Signavio.Portal.Analytics = {}; };
if(!Signavio.Portal.Analytics.Widgets){  Signavio.Portal.Analytics.Widgets = {}; };


new function(){
	
	Signavio.Portal.Analytics.Widgets.ExampleWidget = {
			
		construct: function() {
			// Call super class
			arguments.callee.$.construct.apply(this, arguments);
			this.icon = Signavio.Config.EXPLORER_PATH + "/src/img/famfamfam/database.png";
			this.store = new Ext.data.SimpleStore({fields:[], data:[]});
		},
		
		visible: false,
		
		getPanel: function() {
			this.initPanel();
			return this.panel;
		},
		
		getRegion: function(){
			return "instanceview.chart";
		},
		
		initPanel: function() {
			
			this.panel = new Ext.Panel({
				border	: false,
				anchor	: "100% 100%",
				title: "Prozessinstanzen",
				html: "<div id='analytics_example_widget_content' style='margin-top: 26px; margin-left: 5px;'>" +
						"Anzahl von Prozessinstanzen in selektierter Menge: ?" +
					"</div>"
			});

		},
		
		update: function(filter){
			
			if (this.visible) {
				var url = Signavio.Portal.Config.PLATFORM + "/analyticsnrinstances";
				var params = {filterId : filter.id};
				Signavio.Core.Stores.RequestManager.doGet(url, this.onLoad.bind(this), params);
			}
			
		},
		
		onLoad: function(response){
			var data = response.pluck("rep")[0];
			this.panel.body.update("<div id='analytics_example_widget_content' style='margin-top: 26px; margin-left: 5px;'>" +
						"Anzahl von Prozessinstanzen in selektierter Menge: " + data +
					"</div>");

		},
	};
	
	Signavio.Portal.Analytics.Widgets.ExampleWidget = Signavio.Portal.Analytics.PanelWidget.extend(Signavio.Portal.Analytics.Widgets.ExampleWidget);
}();